<template>
  <div>
    <div id="head">
      <div>查询结果：{{ result }}</div>
      <div>
        <el-button type="primary" size="mini" @click="getGather()">
          获取 / 刷新报告
          {{ computePrice }}
        </el-button>
      </div>
      <div>
        上次查询时间：{{ time }}
      </div>
    </div>
    <p id="describe">{{ explain }}</p>
  </div>
</template>

<script>
  import {getBalance} from "@/api/system/user";

  export default {
    name: "queryHead",
    props: {
      explain: {
        default: '',
        type: String
      },
      result: {
        default: '暂无',
        type: String
      },
      time: {
        default: '暂无',
        type: String
      },
      price: {
        required: true,
        type: Number
      }
    },
    data() {
      return {
        balance: undefined,
      }
    },
    computed: {
      computePrice() {
        return this.price > this.balance ? '（余额不足）' : this.zeroTwo(this.price)
      }
    },
    mounted() {
      getBalance().then(response => {
        this.balance = response.data
      })
    },
    updated() {
      getBalance().then(response => {
        this.balance = response.data
      })
    },
    methods: {
      getGather() {
        if (this.price > this.balance) {
          this.$bus.$emit('openPay')
        } else {
          this.$emit('query')
        }
      }
    }
  }
</script>

<style scoped>

  #head {
    width: 50vw;
    margin: 0px auto 8px;
    display: flex;
    justify-content: space-around;
  }

  #describe {
    margin: 5px 0 5px;
    font-weight: bold;
    text-align: center;
  }
</style>
